package ar.edu.unrn.lia.dao.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Named;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import ar.edu.unrn.lia.dao.TasaInteresDAO;
import ar.edu.unrn.lia.generic.GenericDaoJpaImpl;
import ar.edu.unrn.lia.model.AlquilerCuota;
import ar.edu.unrn.lia.model.AlquilerCuota.CoutaEstado;
import ar.edu.unrn.lia.model.TasaInteres;
import ar.edu.unrn.lia.util.FuncionesDate;

@Named("tasaInteresDAO")
public class TasaInteresDAOImpl extends GenericDaoJpaImpl<TasaInteres, Long>
		implements TasaInteresDAO, Serializable {

	public Predicate[] getSearchPredicates(Root<TasaInteres> root,
			Map<String, String> filters) {

		CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
		List<Predicate> predicatesList = new ArrayList<Predicate>();
		root.alias("entity");

		return predicatesList.toArray(new Predicate[predicatesList.size()]);
	}
	
	
	public TasaInteres tasaInteresFechaHoy()
	{		
		try {
			return  (TasaInteres) entityManager.createQuery
					("from " + this.entityClass.getName() + " ti "
							+ "where MONTH(ti.fecha)= :mes and  "
							+ "YEAR(ti.fecha) = :anio ").
					setParameter("mes", FuncionesDate.mesHoy()).
					setParameter("anio", FuncionesDate.anioHoy()).	
					getSingleResult();   
		} catch (Exception e) {
			return null;
		}
		
		
	}

}